<template>
	<el-form label-width="130px" :model="form" :rules="rules" ref="queryForm">
		<el-row>
			<el-col :span="12">
				<el-form-item label="摄像机名称" prop="name">
					<el-input v-model="form.name" style="width: 190px;"></el-input>
				</el-form-item>
				
				<el-form-item label="高点监控点位" prop="hmpId">
					<el-input v-model="form.hmpId" style="width: 190px;"></el-input>
				</el-form-item>
				<el-form-item label="编码格式" prop="codedFormat">
					<el-input v-model="form.codedFormat" style="width: 190px;"></el-input>
				</el-form-item>
				
				<el-form-item label="图像分辨率" prop="imageResolution">
					<el-input v-model="form.imageResolution" style="width: 190px;"></el-input>
				</el-form-item>

				<el-form-item label="本地存储时间" prop="localtime">
					<el-input v-model="form.localtime" style="width: 190px;"></el-input>
				</el-form-item>

				<el-form-item label="联系人" prop="contact">
					<el-input v-model="form.contact" style="width: 190px;"></el-input>
				</el-form-item>
			</el-col>
			<el-col :span="12">

				<el-form-item label="联系电话" prop="contactNumber">
					<el-input v-model="form.contactNumber" style="width: 190px;"
					@input="e => regOnlyNumSpot(e, form, 'contactNumber', 0)" maxlength="11"></el-input>
				</el-form-item>
				<el-form-item label="功率" prop="power">
					<el-input v-model="form.power" style="width: 190px;"
					@input="e => regOnlyNumSpot(e, form, 'power', 2)"></el-input>
				</el-form-item>
				<el-form-item label="品牌" prop="brand">
					<el-input v-model="form.brand" style="width: 190px;"></el-input>
				</el-form-item>
				<el-form-item label="型号" prop="model">
					<el-input v-model="form.model" style="width: 190px;"></el-input>
				</el-form-item>
				
				<el-form-item label="输入电压" prop="voltage">
					<el-input v-model="form.voltage" style="width: 190px;"></el-input>
				</el-form-item>
				
			</el-col>
		</el-row>
		<div style="display: flex;justify-content: flex-end;">
			<el-button @click="closethis()" @keyup.prevent @keydown.enter.prevent>取消</el-button>
			<el-button type="primary" @click="submit(queryForm)" @keyup.prevent @keydown.enter.prevent>确定</el-button>
		</div>
	</el-form>
</template>

<script setup>
	import {
		ref,
		reactive,
		onMounted
	} from 'vue'
	import {
		ElMessage
	} from 'element-plus'

	import {
		commonInterface
	} from '@/api/common/common'
	
	import {
		regOnlyNumSpot
	} from '@/utils/reg'



	const emit = defineEmits(['getList', 'closeWindow'])
	const props = defineProps(['editData', 'code'])

	const form = ref({
		code:''
	})

	const queryForm = ref('')

	//必填项
	const rules = reactive({
		name: [{
			required: true,
			message: "此选项不能为空!",
			trigger: "blur"
		}]
	})
	//取消
	const closethis = () => {
		emit('closeWindow')
	}

	//确定
	const submit = async (e) => {
		if (!e) return
		await e.validate((valid) => {
			if (valid) {
				let method = 'post'
				if (props.editData) method = 'put'
				commonInterface('/back/renfang/zhtx/camera/', form.value, method).then(result => {
					if (result.code === 200) {
						ElMessage.success(result.msg)
						emit('closeWindow')
						emit('getList')
					} else {
						ElMessage.error(result.msg)
					}
				})
			}
		})
	}

	onMounted(() => {
		form.value.code = props.code
		if (props.editData) form.value = props.editData
	})
</script>

<style>
</style>